package fms.models;
 
import java.util.List;
 
import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;

import fms.classes.Form3_1;
 
 
public class Form3_1DAO {
 
    private SqlSessionFactory sqlSessionFactory;
 
    public Form3_1DAO(){
    	try{
    		sqlSessionFactory = MyBatisSqlConnection.getSqlSessionFactory();
    	}catch(Exception e) {
    		System.out.println("failed to get sqlSessionFactory");
    	}
    }
 
    /**Returns the list of all Form3_1 instances from the database*/
    @SuppressWarnings("unchecked")
    public List<Form3_1> selectAll(){
 
        SqlSession session = sqlSessionFactory.openSession();
 
        try {
            List<Form3_1> list = session.selectList("Form3_1.getAll");
            return list;
        } finally {
            session.close();
        }
    }
 
    /**Returns a Form3_1 instance from the database*/
    public Form3_1 selectById(int rca_form_no){
 
        SqlSession session = sqlSessionFactory.openSession();
 
        try {
            Form3_1 form3_1 = (Form3_1) session.selectOne("Form3_1.getById", rca_form_no);
            return form3_1;
        } finally {
            session.close();
        }
    }
 
    /**Updates an instance of Form3_1 in the database*/
    public void update(Form3_1 form3_1){
 
        SqlSession session = sqlSessionFactory.openSession();
 
        try {
            session.update("Form3_1.update", form3_1);
            session.commit();
        } finally {
            session.close();
        }
    }
 
    /** Insert an instance of Form3_1 into the database*/
    public void insert(Form3_1 form3_1){
 
        SqlSession session = sqlSessionFactory.openSession();
 
        try {
            session.insert("Form3_1.insert", form3_1);
            session.commit();
        } finally {
            session.close();
        }
    }
 
    /** Delete an instance of Form3_1 from the database*/
    public void delete(int rca_form_no){
 
        SqlSession session = sqlSessionFactory.openSession();
 
        try {
            session.delete("Form3_1.deleteById", rca_form_no);
            session.commit();
        } finally {
            session.close();
        }
    }
}